<template>
    <div>
        <!-- <h3>新闻列表组件</h3> -->
        <ul class="mui-table-view">
				<!-- <li class="mui-table-view-cell mui-media" v-for="item in (newslist[0].message)" :key="item.id"> -->
				<li class="mui-table-view-cell mui-media" v-for="item in newslist" :key="item.id">
					<router-link :to="'/home/newsinfo/' + item.id">
						<img class="mui-media-object mui-pull-left" :src="item.img_url">
						<div class="mui-media-body">
							<h1>{{item.title}}</h1>
							<p class='mui-ellipsis'>
                                <span>发表时间：{{item.add_time | dateFormat }}</span>
                                <span>点击：{{item.click}}次</span>
                            </p>
						</div>
					</router-link>
				</li>			

			</ul>
        
    </div>
</template>

<script>
import {Toast} from "mint-ui";
export default {
    data() {
        return {
            api:"api/getnewslist",
            newslist: [
            // {
            //     "status": 0,
            // 	"message": [
            //         {
            //             "id": "1",
            //             "title": "新闻1",
            //             "add_time": "2011-08-12T20:17:46.384Z",
            //             "zhaiyao": "测试项目1",
            //             "click": "1",
            //             "img_url": "http://e.hiphotos.baidu.com/image/pic/item/d788d43f8794a4c2f12be52b00f41bd5ad6e39a1.jpg"           
            //         },
            //         {
            //             "id": "3",
            //             "title": "新闻2",
            //             "add_time": "2019-08-12T20:17:46.384Z",
            //             "zhaiyao": "测试项目2",
            //             "click": "25",
            //             "img_url": ""           
            //         },
            // 		{
            //             "id": "5",
            //             "title": "新闻3",
            //             "add_time": "2025-08-12T20:17:46.384Z",
            //             "zhaiyao": "测试项目3",
            //             "click": "99",
            //             "img_url": "http://g.hiphotos.baidu.com/image/pic/item/d1160924ab18972b0aa9c1d2e8cd7b899e510a13.jpg"           
            //         }
            //     ]
            // }
           ]
        }
    },
    created(){
        this.getNewslist();
    },
    methods:{
        getNewslist(){
            this.$http.get(this.api).then(result => {
                console.log(result);
                if(result.body.status === 0){
                    this.newslist = result.body.message;
                } else{
                    Toast("新闻列表加载失败！");
                }
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.mui-table-view{
    li{
        h1{
            font-size: 14px;
        }
        .mui-ellipsis{
            font-size: 12px;
            color: #226aff;
            display: flex;
            justify-content: space-between;
        }
        img{
            width: 100%;
            height: 45px;
        }
    }
}

</style>
